package com.shixulin.controller;
import com.shixulin.domain.ResponseResult;
import com.shixulin.entity.DTO.UserAnswerDTO;
import com.shixulin.entity.UserAnswer;
import com.shixulin.entity.UserExam;
import com.shixulin.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.util.List;

@RestController
@RequestMapping("/user")
public class userController {
    @Autowired
    private CourseInfoService courseInfoService;

    @Autowired
    private ExamPaperService examPaperService;

    @Autowired
    private PaperQuestionService paperQuestionService;

    @Autowired
    private UserExamService userExamService;

    @Autowired
    private UserAnswerService userAnswerService;

    @Autowired
    private MyExamService myExamService;

    @GetMapping("/getCourseData/{subjectId}")
    public ResponseResult getCourseData(@PathVariable("subjectId") int subjectId){
        return courseInfoService.getCourseData(subjectId);
    }

    @GetMapping("/getExamPaper/{subjectId}")
    public ResponseResult getExamPaper(@PathVariable("subjectId") int subjectId){
        return examPaperService.getExamPaper(subjectId);
    }

    //获取考试试卷
    @GetMapping("/getPaper/{paperId}")
    public ResponseResult getPaper(@PathVariable("paperId") int paperId){
        return examPaperService.getPaper(paperId);
    }

    //获取考试试卷题目
    @GetMapping("/getPaperQuestion/{paperId}")
    public ResponseResult getPaperQuestion(@PathVariable int paperId){
        return paperQuestionService.getPaperQuestion(paperId);
    }

    //判断是否已经考试了
    @PostMapping("/isStatus")
    public ResponseResult isStatus(@RequestBody UserAnswerDTO userAnswerDTO){
        int userId = userAnswerDTO.getUserId();
        int paperId = userAnswerDTO.getPaperId();
      return   userExamService.isStatus(userId,paperId);
    }
    //保存试卷状态
    @PostMapping("/saveUserExam")
    public ResponseResult saveUserExam(@RequestBody UserExam userExam){
        return userExamService.saveUserExam(userExam);
    }
    //保存用户答题
    @PostMapping("/saveUserAnswer")
    public ResponseResult saveUserAnswer(@RequestBody List<UserAnswer> userAnswer){

        return userAnswerService.saveUserAnswer(userAnswer);
    }
    //获取已经考试的试卷
    @GetMapping("/getMyExam/{subjectId}")
    public ResponseResult getMyExam(@PathVariable("subjectId") int subjectId){

        return myExamService.getMyExam(subjectId);
    }
    //获取用户的答案
    @GetMapping("/getUserAnswer/{userId}/{paperId}/{examStatus}")
    public ResponseResult getUserAnswer(@PathVariable("userId") int userId,@PathVariable("paperId") int paperId ,
                                        @PathVariable("examStatus") int examStatus ){
        return userAnswerService.getUserAnswer(userId,paperId,examStatus);

    }
}
